<?php  
include_once "commonDao.php"; 
class exampleDao extends commonDao {  
    
    public function __construct(){
        parent::__construct();
        $this->table_name = 'example';
        $this->fields = 'title, img';
    } 
      
    /** 
     * 新增
     * @param $user 
     */  
    public function addExample($user) {  
        $user = $this->init_db()->build_key($user, $this->fields);  
        return $this->init_db()->insert($user, $this->table_name);  
    } 

    /**
     * 添加记录
     * @param  array $arr 
     * @return [type]      
     */
    function exampleAdd($arr){
        $id = $this->init_db()->insert($arr, $this->table_name);
        return $id;
    } 
      
    /** 
     * 通过ID获取一条数据 
     * @param unknown_type $id 
     */  
    public function getOne($id) {  
        return $this->init_db()->get_one($id, $this->table_name);  
    } 

    /**
     * 根据字段值获取一条数据
     * @param  array $arr 
     * @return array      
     */
    function getExampleByField($arr) { 
        return $this->init_db()->get_one_by_field($arr, $this->table_name);
    } 

    /**
     * 获得列表数据
     * @param  integer $num    
     * @param  integer $offest 
     * @param  array   $field  
     * @param  string  $id_key 
     * @param  string  $sort   
     * @return array          
     */
    function getExampleList($field = array(), $num = '', $id_key = 'id', $sort = 'DESC'){
        //$result = $this->dao->db->get_all($this->table_name, $num, $offest, $field , $id_key , $sort);
        $result = $this->getList($this->table_name, $field , $num, $id_key , $sort);
        return $result;
    }

    /**
     * 数据更新
     * @param  array $arr   更新数组
     * @param  array $field  条件数组
     * @return [type]        
     */
    function exampleUpdate($arr, $field){
        $res = $this->init_db()->update_by_field($arr, $field, $this->table_name);
        return $res;
    }

    /**
     * 删除数据
     * @param  array $field 删除条件
     * @return [type]       
     */
    function exampleDel($field){
        return $this->init_db()->delete_by_field($field, $this->table_name);
    }

} 